using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VGLOPITEM
    {
        public DataRow Convert2GLOPITEM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryGLOPITEM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["GLOMANDANT"] = " ".PadRight(2 ); 
         dwReturn["GLOACCOUNT"] = " ".PadRight(8 ); 
         dwReturn["GLOITEM"] = " ".PadRight(10 ); 
         dwReturn["GLOAMICUD"] = " ".PadRight(0 ); 
         dwReturn["GLOAMFCUD"] = " ".PadRight(0 ); 
         dwReturn["GLOAMICUC"] = " ".PadRight(0 ); 
         dwReturn["GLOAMFCUC"] = " ".PadRight(0 ); 
         dwReturn["GLOWEXRATE"] = " ".PadRight(0 ); 
         dwReturn["GLOBOOKDAT"] = " ".PadRight(0 ); 
         dwReturn["GLOINVDAT"] = " ".PadRight(0 ); 
         dwReturn["GLOVALUEDAT"] = " ".PadRight(0 ); 
         dwReturn["GLOPAYDAT"] = " ".PadRight(0 ); 
         dwReturn["GLOINVNO"] = " ".PadRight(8 ); 
         dwReturn["GLOOPSUFF"] = " ".PadRight(2 ); 
         dwReturn["GLOCURRENCY"] = " ".PadRight(3 ); 
         dwReturn["GLOADINVNO"] = " ".PadRight(12 ); 
         dwReturn["GLOTOP"] = " ".PadRight(4 ); 
         dwReturn["GLOCDAMICU"] = " ".PadRight(0 ); 
         dwReturn["GLOCDAMFCU"] = " ".PadRight(0 ); 
         dwReturn["GLOCDDAYS1"] = " ".PadRight(0 ); 
         dwReturn["GLOCDPERC1"] = " ".PadRight(0 ); 
         dwReturn["GLOCDDAYS2"] = " ".PadRight(0 ); 
         dwReturn["GLOCDPERC2"] = " ".PadRight(0 ); 
         dwReturn["GLOCDDAYSN"] = " ".PadRight(0 ); 
         dwReturn["GLOACCKIND"] = " ".PadRight(1 ); 
         dwReturn["GLOFILLER1"] = " ".PadRight(42 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapGLOPITEM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveGLOPITEM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryGLOPITEM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapGLOPITEM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertGLOPITEM(dwLocal, ITXDBVERSION);
            }
            UpdateGLOPITEM(dwLocal);
        }
        public void InsertGLOPITEM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO GLOPITEM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryGLOPITEM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GLOPITEM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM GLOPITEM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "GLOPITEM";
            Return = Result;
            return Return;
        }
        public void DeleteGLOPITEM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM GLOPITEM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateGLOPITEM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE GLOPITEM SET "
                    +"GLOMANDANT= :GLOMANDANT,"
                    +"GLOACCOUNT= :GLOACCOUNT,"
                    +"GLOITEM= :GLOITEM,"
                    +"GLOAMICUD= :GLOAMICUD,"
                    +"GLOAMFCUD= :GLOAMFCUD,"
                    +"GLOAMICUC= :GLOAMICUC,"
                    +"GLOAMFCUC= :GLOAMFCUC,"
                    +"GLOWEXRATE= :GLOWEXRATE,"
                    +"GLOBOOKDAT= :GLOBOOKDAT,"
                    +"GLOINVDAT= :GLOINVDAT,"
                    +"GLOVALUEDAT= :GLOVALUEDAT,"
                    +"GLOPAYDAT= :GLOPAYDAT,"
                    +"GLOINVNO= :GLOINVNO,"
                    +"GLOOPSUFF= :GLOOPSUFF,"
                    +"GLOCURRENCY= :GLOCURRENCY,"
                    +"GLOADINVNO= :GLOADINVNO,"
                    +"GLOTOP= :GLOTOP,"
                    +"GLOCDAMICU= :GLOCDAMICU,"
                    +"GLOCDAMFCU= :GLOCDAMFCU,"
                    +"GLOCDDAYS1= :GLOCDDAYS1,"
                    +"GLOCDPERC1= :GLOCDPERC1,"
                    +"GLOCDDAYS2= :GLOCDDAYS2,"
                    +"GLOCDPERC2= :GLOCDPERC2,"
                    +"GLOCDDAYSN= :GLOCDDAYSN,"
                    +"GLOACCKIND= :GLOACCKIND,"
                    +"GLOFILLER1= :GLOFILLER1,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("GLOMANDANT", OracleType.NVarChar).Value = dwData["GLOMANDANT"].ToString(); 
          or1.Parameters.Add("GLOACCOUNT", OracleType.NVarChar).Value = dwData["GLOACCOUNT"].ToString(); 
          or1.Parameters.Add("GLOITEM", OracleType.NVarChar).Value = dwData["GLOITEM"].ToString(); 
          or1.Parameters.Add("GLOAMICUD", OracleType.NVarChar).Value = dwData["GLOAMICUD"].ToString(); 
          or1.Parameters.Add("GLOAMFCUD", OracleType.NVarChar).Value = dwData["GLOAMFCUD"].ToString(); 
          or1.Parameters.Add("GLOAMICUC", OracleType.NVarChar).Value = dwData["GLOAMICUC"].ToString(); 
          or1.Parameters.Add("GLOAMFCUC", OracleType.NVarChar).Value = dwData["GLOAMFCUC"].ToString(); 
          or1.Parameters.Add("GLOWEXRATE", OracleType.NVarChar).Value = dwData["GLOWEXRATE"].ToString(); 
          or1.Parameters.Add("GLOBOOKDAT", OracleType.NVarChar).Value = dwData["GLOBOOKDAT"].ToString(); 
          or1.Parameters.Add("GLOINVDAT", OracleType.NVarChar).Value = dwData["GLOINVDAT"].ToString(); 
          or1.Parameters.Add("GLOVALUEDAT", OracleType.NVarChar).Value = dwData["GLOVALUEDAT"].ToString(); 
          or1.Parameters.Add("GLOPAYDAT", OracleType.NVarChar).Value = dwData["GLOPAYDAT"].ToString(); 
          or1.Parameters.Add("GLOINVNO", OracleType.NVarChar).Value = dwData["GLOINVNO"].ToString(); 
          or1.Parameters.Add("GLOOPSUFF", OracleType.NVarChar).Value = dwData["GLOOPSUFF"].ToString(); 
          or1.Parameters.Add("GLOCURRENCY", OracleType.NVarChar).Value = dwData["GLOCURRENCY"].ToString(); 
          or1.Parameters.Add("GLOADINVNO", OracleType.NVarChar).Value = dwData["GLOADINVNO"].ToString(); 
          or1.Parameters.Add("GLOTOP", OracleType.NVarChar).Value = dwData["GLOTOP"].ToString(); 
          or1.Parameters.Add("GLOCDAMICU", OracleType.NVarChar).Value = dwData["GLOCDAMICU"].ToString(); 
          or1.Parameters.Add("GLOCDAMFCU", OracleType.NVarChar).Value = dwData["GLOCDAMFCU"].ToString(); 
          or1.Parameters.Add("GLOCDDAYS1", OracleType.NVarChar).Value = dwData["GLOCDDAYS1"].ToString(); 
          or1.Parameters.Add("GLOCDPERC1", OracleType.NVarChar).Value = dwData["GLOCDPERC1"].ToString(); 
          or1.Parameters.Add("GLOCDDAYS2", OracleType.NVarChar).Value = dwData["GLOCDDAYS2"].ToString(); 
          or1.Parameters.Add("GLOCDPERC2", OracleType.NVarChar).Value = dwData["GLOCDPERC2"].ToString(); 
          or1.Parameters.Add("GLOCDDAYSN", OracleType.NVarChar).Value = dwData["GLOCDDAYSN"].ToString(); 
          or1.Parameters.Add("GLOACCKIND", OracleType.NVarChar).Value = dwData["GLOACCKIND"].ToString(); 
          or1.Parameters.Add("GLOFILLER1", OracleType.NVarChar).Value = dwData["GLOFILLER1"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
